package com.rem.designPattern.iterator迭代器;

import java.util.ArrayList;
import java.util.List;

/**
 * 抽象容器
 *
 * @author Rem
 * @date 2022-11-23
 */
public interface StudentAggregate {

    void addStudent(Student student);

    void removeStudent(Student student);

    StudentIterator getStudentIterator();
}

/**
 * 具体聚合对象
 */
class StudentAggregateImpl implements StudentAggregate {

    private final List<Student> list = new ArrayList<>();

    @Override
    public void addStudent(Student student) {
        this.list.add(student);
    }

    @Override
    public void removeStudent(Student student) {
        this.list.remove(student);
    }

    @Override
    public StudentIterator getStudentIterator() {
        return new StudentIteratorImpl(list);
    }
}